package com.fm.app03.Activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.Toast;

import com.fm.app03.MainActivity;
import com.fm.app03.R;

import java.util.ArrayList;
import java.util.List;

public class registerActivity extends AppCompatActivity {

    private EditText editTextUsername;
    private EditText editTextPassword;
    private EditText editTextConfirmPassword;
    private RadioButton radioMale;
    private RadioButton radioFemale;
    private Spinner spinnerCity;
    private CheckBox checkboxHobby1, checkboxHobby2, checkboxHobby3, checkboxHobby4, checkboxHobby5, checkboxHobby6, checkboxHobby7;
    private Button registerButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        editTextUsername = findViewById(R.id.editTextUsername);
        editTextPassword = findViewById(R.id.editTextPassword);
        editTextConfirmPassword = findViewById(R.id.editTextConfirmPassword);
        radioMale = findViewById(R.id.radioMale);
        radioFemale = findViewById(R.id.radioFemale);
        spinnerCity = findViewById(R.id.spinnerCity);
        checkboxHobby1 = findViewById(R.id.checkboxHobby1);
        checkboxHobby2 = findViewById(R.id.checkboxHobby2);
        checkboxHobby3 = findViewById(R.id.checkboxHobby3);
        checkboxHobby4 = findViewById(R.id.checkboxHobby4);
        checkboxHobby5 = findViewById(R.id.checkboxHobby5);
        checkboxHobby6 = findViewById(R.id.checkboxHobby6);
        checkboxHobby7 = findViewById(R.id.checkboxHobby7);
        registerButton = findViewById(R.id.registerButton);

        registerButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                show("点击了注册按钮");
                Log.d("fm", "开始获取");
                String username = editTextUsername.getText().toString();
                String password = editTextPassword.getText().toString();
                String confirmPassword = editTextConfirmPassword.getText().toString();
                String gender = radioMale.isChecked() ? "男" : (radioFemale.isChecked() ? "女" : "");
                String city = spinnerCity.getSelectedItem().toString();
                List<String> selectedHobbies = new ArrayList<>();
                if (checkboxHobby1.isChecked()) {
                    selectedHobbies.add(checkboxHobby1.getText().toString());
                }
                if (checkboxHobby2.isChecked()) {
                    selectedHobbies.add(checkboxHobby2.getText().toString());
                }
                if (checkboxHobby3.isChecked()) {
                    selectedHobbies.add(checkboxHobby3.getText().toString());
                }
                if (checkboxHobby4.isChecked()) {
                    selectedHobbies.add(checkboxHobby4.getText().toString());
                }
                if (checkboxHobby5.isChecked()) {
                    selectedHobbies.add(checkboxHobby5.getText().toString());
                }
                if (checkboxHobby6.isChecked()) {
                    selectedHobbies.add(checkboxHobby6.getText().toString());
                }
                if (checkboxHobby7.isChecked()) {
                    selectedHobbies.add(checkboxHobby7.getText().toString());
                }


                // 输出获取的值
                Log.i("RegisterActivity", "Username: " + username);
                Log.i("RegisterActivity", "Password: " + password);
                Log.i("RegisterActivity", "Confirm Password: " + confirmPassword);
                Log.i("RegisterActivity", "Gender: " + gender);
                Log.i("RegisterActivity", "City: " + city);
                Log.i("RegisterActivity", "Selected Hobbies: " + selectedHobbies);

            }
        });
    }



    private void show(String str){
        Toast.makeText(registerActivity.this, str, Toast.LENGTH_SHORT).show();
    }

}